﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Serialization;
using DTO.Reports;

namespace DTO
{
    [DataContract]
    public class IndexRow
    {

        public int OrderField { get; set; }

        [DataMember]
        public RespondentBase Resp { get; set; }

        [DataMember]
        public String Position { get; set; }

        [DataMember]
        public double Index { get; set; }

        //BMK проверит IndexLider на адекватность модели
        private IndexLider indexLider;

        [DataMember]
        public IndexLider IndexLider
        {
            get
            {
                return indexLider;
            }
            set
            {
                indexLider = value;
            }
        }


        [DataMember]
        public double IndexHarmony { get; set; }

        //просмотреть класс Section на предмет TreeItem
        private List<SectionIndex> sectionIndex = new List<SectionIndex>();

        [DataMember]
        public List<SectionIndex> SectionIndex
        {
            get
            {
                return sectionIndex;
            }
            set
            {
                sectionIndex = value;
            }
        }

        public void GetIndexeLider(int TermID)
        {
            /*
              List<SectionIndex> parents = this.SectionsIndex.Where(x => x.Sec.SectionTerms.Where(y => y.IDTerm == TermID).Single().Section == null && x.Sec.SectionTerms.Where(y => y.IDTerm == TermID).FirstOrDefault().Order != "7").ToList();
            this.indexLider.Index = parents[0].Index;
            this.indexLider.SectionNumber = parents[0].Sec.GetNumber(TermID);
            this.indexLider.StringView = this.indexLider.ToString();
            foreach (SectionIndex SI in parents)
            {
                if (SI.Index > this.IndexLider.Index)
                {
                    this.indexLider.Index = SI.Index;
                    this.indexLider.SectionNumber = SI.Sec.GetNumber(TermID);
                    this.indexLider.StringView = this.indexLider.ToString();
                }
            }
             */
        }

        public double GetSumParentSection(int TermID)
        {
            /*
             *             double Sum = 0;
            foreach (SectionIndex SI in SectionsIndex)
            {
                if (SI.Sec.SectionTerms.Where(x=>x.IDTerm == TermID).Single().Section == null && SI.Sec.SectionTerms.Where(x => x.IDTerm == TermID).FirstOrDefault().Order != "7") //если раздел верхнего уровня и не дполнительные данные
                {
                    Sum += SI.Index * SI.Weight;
                }
            }
            return Sum;
             */
            return 0.0;
        }

        public double GetHarmon(int TermID)
        {
            /*
             * double Sum = 0;
            foreach (SectionIndex SI in SectionsIndex)
            {
                if (SI.Sec.SectionTerms.Where(x => x.IDTerm == TermID).Single().Section == null && SI.Sec.SectionTerms.Where(x => x.IDTerm == TermID).FirstOrDefault().Order != "7") //если раздел верхнего уровня
                {
                    Sum += SI.Index;
                }
            }
            return Sum / this.IndexLider.Index;
             */
            return 0.0;
        }
    }
}
